-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Base python solver #2068
Conversation
def ComputeDeltaTime(self): | ||
pass | ||
|
||
def Initialize(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can agree that the strategies will called in this cases, and then we can call this methods on the strategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally left this empty since theoretically a solver can have no strategy
e.g. an FSI solver does not have a strategy itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean that it cannot have a strategy inside? it may even have multiple as long as they are hidden in the api...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can have 0 to n strategies inside, that why I left it empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i misread what you wrote.
def AdvanceInTime(self): | ||
pass | ||
|
||
def ComputeDeltaTime(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can return the current delta time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, good suggestion, esp for the structure since it cannot compute Dt yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this function on the external interface of the base class? I don't think it is used outside of the solver right now, and we could think of solvers that don't have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also true
Will remove it, the user should call AdvanceInTime
def AddDofs(self): | ||
pass | ||
|
||
def GetMinimumBufferSize(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can return 2 at least
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a default, the minimum buffer size. Obviously the idea is to override in the solvers
|
||
def ReadModelPart(self): | ||
# TODO replace the functions in the solvers in Fluid and Structure | ||
KratosMultiphysics.Logger.PrintInfo("::[PythonSolver]::", "Reading model part.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I was wondering is if we should "hard-code" labels like this. If we call it from a derived solver, is it more useful for the label to be "[PythonSolver]" or "[DynamicStructuralSolver]"? I don't have a strong opinion on this, but it is a discussion I think we should have at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thing, I remember or something... That in my analysis I added a method to return the label, that is overrided in each solver, so the solver always knows the name of the solver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easy to add a GetSolverName function that every solver implements
Might be useful if several solvers are used, which is likely to be the case in the future
I dont habe a strong opinion though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another point for hardcoding is that if a solver calls the functions of the baseclass (e.g. Initialize
) then we would have multiple Initializing done
prints with the same solver name which I think would be quite confusing
KratosMultiphysics.Logger.PrintInfo("ModelPart", self.main_model_part) | ||
KratosMultiphysics.Logger.PrintInfo("::[PythonSolver]:: ", "Finished reading model part.") | ||
|
||
def PrepareModelPartForSolver(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, does this need to be a public method of the solver? Or should it work internally? Also, the name is a bit strange... If we are "the solver", why should we prepare something "for the solver"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good it is a public method, since one may want to override it. an example is if you have a "strange" problem and you need to build submodelparts on your own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be public
For fluids this is the function that would replace the elements, whereas in structure we e.g. assign the materials
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am making minor comments.
another one is that
def validate_and_transfer_matching_settings
i guess should be done in c++ with its own tests etc
def AddDofs(self): | ||
pass | ||
|
||
def GetMinimumBufferSize(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a static solver, 1 is enough...
KratosMultiphysics.Logger.PrintInfo("ModelPart", self.main_model_part) | ||
KratosMultiphysics.Logger.PrintInfo("::[PythonSolver]:: ", "Finished reading model part.") | ||
|
||
def PrepareModelPartForSolver(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good it is a public method, since one may want to override it. an example is if you have a "strange" problem and you need to build submodelparts on your own
def GetMinimumBufferSize(self): | ||
pass | ||
|
||
def ReadModelPart(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we call this ImportModelPart, exactly with the implementation and you propose...that is, also followed by a function "Prepare"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for me
I used a different name because others (e.g. the FSI solvers) are still using ImportModelPart
and I would have silently broken those
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this argument makes sense.
def ComputeDeltaTime(self): | ||
pass | ||
|
||
def Initialize(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean that it cannot have a strategy inside? it may even have multiple as long as they are hidden in the api...
def Clear(self): | ||
pass | ||
|
||
def GetComputingModelPart(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to say that i invented this ComputingModelPart idea...and i hate it :-(.
I don't have a better idea however
I finished the base-class and the adaption of the Structural Solvers I ran the tests for the involved applications @jcotela I tried to do it also for the Fluid but there is a bit of refactoring needed, so I would prefer if it would be done in a separate PR |
@philbucher I'll make a pass of refactoring for fluid solvers once this is merged. |
ping @KratosMultiphysics/technical-committee |
""" | ||
pass | ||
|
||
def Check(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add some trivial checks (like settings is a Parameter, input file exists, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the type of the input is checked in the constructor
I thought of this function to be called before the SolutionLoop (I will add it to the AnalysisStage)
=> It should call methods like Strategy.Check() to validate if the input is correct
Therefore it cannot validate if the input file has been found
(btw for this one the error is quite clear already:
RuntimeError: Error: Error opening mdpa file : Example.mdpa
)
I did the modifications as requested by @RiccardoRossi => passing the @KratosMultiphysics/technical-committee please have a look since this has to be merged before #2135 After this is merged I will solve the "conflicts" in #2135 to finalize everything |
@philbucher feel free to merge both #2135 and this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am approving. @philbucher wait if someone blocks it tomorrow in the morning and otherwise merge...
@@ -95,7 +95,7 @@ def ExportModelPart(self): | |||
file.close() | |||
KratosMultiphysics.ModelPartIO(name_out_file, KratosMultiphysics.IO.WRITE).WriteModelPart(self.main_model_part) | |||
|
|||
def AdvanceInTime(self): | |||
def AdvanceInTime(self, current_time): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current time can be obtained as
model_part.ProcessInfo[TIME]
why do you need to pass it?
@philbucher I have been doing experiments with a branch, merging this PR and #2135, and for example the fluid does not work anymore, @jcotela do you mind if I repair that? |
""" | ||
raise Exception('Please implement "GetMinimumBufferSize" in your derived solver') | ||
|
||
def ImportModelPart(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two of these, there is the ImportModelPart and the _ImportModelPart, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, deprecated, I see
@loumalouomega please wait with pushing to this Branch, I am fixing FSI and your branch before merging this @jcotela and I know abt the problems, the fluid will be done in a separate PR before #2135 Please give me until this evening then everything should be working |
Don't worry, I am working locally, but right no I am havig problems to make work the model properly with the main model part |
ok, but be aware that I am also working on this I wil push the changes regarding the solver to this branch in ~2hrs and afterwards will integrate the changes in the AnalyisStage-Pr |
e97f752
this is the final set of modifications @KratosMultiphysics/technical-committee there were some minor things I still had to fix, in relation with #2135 , but I didn't change anything major I will merge this branch now to #2135 to fully apply the changes there @RiccardoRossi switching to the Model (=> #2137 ) should now only be a minor change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
I will merge this tmr morning if none blocks/complains |
Apart of the fact that I did not have time to check it until now, this breaks retro compatibility (at least for the FSI app). I guess that this is something we have to live with. In any case, it is not compatible with the current Main script generated by the interface. |
This PR adds a baseclass for the python solvers to the core. This is the second step after having the
AnalysisStage
nowI used the functions that are currently used in the FluidDynamics and the StructuralMechanics Solver and put them to the base-class
This PR is to discuss the interface, I think/hope that it will not be so difficult this time since I am not really doing new things and only collected what exists already
After an agreement has been reached I will add documentation and finish integrating it in the Structural Solver
Having this base class will allow us to call all the functions in the interface in the stage without having to check if a solver actually implements them
Note that I didn't include
Solve
since after @RiccardoRossi s explanation we should call the functions separatelyAlso I did not include
ImportModelPart
, this one is splitted intoReadModelPart
andPrepareModelPartForSolver
The first one is common for the solvers and will not have to be overwritten in most derived solvers.
The second is specific to the solvers and does what the name suggests
This separation is needed one one hand to have the reading implemented only once and also in case the Solver should not read the modelpart (used by the optimization guys)